/*
 * @Author: ziqi jhzq12345678
 * @Date: 2025-01-17 16:00:50
 * @LastEditors: ziqi jhzq12345678
 * @LastEditTime: 2025-01-21 14:31:09
 * @FilePath: /pornhub_app/lib/views/search/result/search_user_cell.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/circle_image.dart';
import 'package:pornhub_app/components/keyword_color/keyword_color.dart';
import 'package:pornhub_app/http/api/api.dart';
import 'package:pornhub_app/model/search/search_user_model.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/views/search/search_controller.dart';

class SearchUserCell extends StatefulWidget {
  final SearchUserModel model;
  const SearchUserCell({super.key, required this.model});
  @override
  State<StatefulWidget> createState() => _SearchUserCell();
}

class _SearchUserCell extends State<SearchUserCell> {
  ValueNotifier<bool> attention = ValueNotifier(false);
  final searchvc = Get.find<SearchPageController>();
  Future attentionUser() async {
    final a = await Api.attentionUser(widget.model.userId!);
    if (a) {
      attention.value = !attention.value;
    }
  }

  @override
  void initState() {
    attention.value = widget.model.attention ?? false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        CircleImage(
          url: widget.model.logo ?? "",
          size: 44.w,
        ),
        SizedBox(
          width: 8.w,
        ),
        Expanded(
          child: KeywordColor(
            title: widget.model.nickName ?? '',
            keyWord: searchvc.keyWord.value,
            style: TextStyle(
              fontSize: 16.w,
              color: Colors.white,
            ),
            kstyle: TextStyle(
              color: COLOR.playerThemColor,
              fontSize: 16.w,
            ),
          ),
        ),
        ValueListenableBuilder(
            valueListenable: attention,
            builder: (context, value, child) {
              return Container(
                width: 64.w,
                height: 27.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(13.w),
                    border: Border.all(
                        color: COLOR.hexColor(value ? '#A4A4B2' : '#B940FF'))),
                child: Text(
                  value ? '已关注' : '关注',
                  style: TextStyle(
                      color: COLOR.hexColor(value ? '#A4A4B2' : '#B940FF'),
                      fontSize: 14.w),
                ),
              ).onOpaqueTap(() {
                attentionUser();
              });
            })
      ],
    ).onOpaqueTap(() {
      // Get.toBloggerDetail(userId: widget.model.userId!);
    });
  }
}
